﻿/**
* Copyright (c) 2008 Glanceguide, Inc.  All rights reserved. 
* http://www.glanceguide.com
* Decompiling, reverse engineering, copying or unauthorized redistribution is prohibited.    
*
* ggFLVPlayback class extends FLVPlayback (AC3)
* Intercepts the FLVPlayback player and records important metrics before returning back control.
*
* NOTE: Does NOT support multiple video players per FLVPlayback
*
**/

package com.nielsen
{
 import fl.video.FLVPlayback;
	import fl.video.MetadataEvent;
	import fl.video.SoundEvent;
	import fl.video.VideoEvent;
	import flash.events.NetStatusEvent;
	
	import flash.utils.setInterval; 

    public class ggFLVPlayback extends FLVPlayback 
	{
   private var _videoInfo:String; 
   
		public function ggFLVPlayback( )
		{
			// Register events
			this.addEventListener( fl.video.MetadataEvent.METADATA_RECEIVED, onMetaDataReceived );
			this.addEventListener( fl.video.SoundEvent.SOUND_UPDATE, onSoundUpdate );
			this.addEventListener( fl.video.VideoEvent.PLAYING_STATE_ENTERED, onPlayingStateEntered );
			this.addEventListener( fl.video.VideoEvent.STOPPED_STATE_ENTERED, onStoppedStateEntered );
			this.addEventListener( flash.events.NetStatusEvent.NET_STATUS, onNetStatus );
			setInterval( function( flvpb:Object ){ ggCom.getInstance( ).PM( "E49", this.playheadTime ); }, 2000, this );
			 
			// Return control to FLVPLayback
			super( );
		} 

		// videoinfo for the subsequent Play call; title, vidtype etc.
		public function setVideoInfo(vi:String)
		{
      _videoInfo = vi;		
		}

	
		// Sound Event
		private function onSoundUpdate( soundObj:Object )
		{
		   ggCom.getInstance( ).PM( "sound", this.volume );
		}
		
		// Net Status Event
		private function onNetStatus( metaObj:Object )
		{
			ggCom.getInstance( ).PM( "onStatus", metaObj.info.code, this.playheadTime );
		}
		
		// Load/Unload Event
		private function onMetaDataReceived( metaObj:Object )
		{
			ggCom.getInstance( ).PM( "E4" );
			ggCom.getInstance( ).PM( "E3", this.metadata, this.getVideoPlayer( 0 ).source, _videoInfo );
		}

		// Play Event
		private function onPlayingStateEntered( playObj:Object )
		{
		   ggCom.getInstance( ).PM( "E5", playObj.playheadTime );
		}
		
		// Complete/Stop Event		
		private function onStoppedStateEntered( stopObj:Object )
		{
			ggCom.getInstance( ).PM( "E7", null, stopObj.playheadTime );
		}
		
		// Seek override
		public override function seek( offset:Number ) : void 
	   	{
			// Send seek event to GlanceGuide
			ggCom.getInstance( ).PM( "E8", offset.toFixed(2), this.playheadTime );  
			
			// Return control to program
			super.seek( offset );
		}
		
		// Pause override
		public override function pause( ) : void 
		{
			// Send pause event to GlanceGuide
			ggCom.getInstance( ).PM( "E6", this.playheadTime ); 
			
			// Return control to FLVPLayback
			super.pause( );
		}
		
   // stop override
		public override function stop( ) : void 
		{
			// Send pause event to GlanceGuide
			ggCom.getInstance( ).PM( "E7", this.playheadTime ); 
			
			// Return control to FLVPLayback
			super.stop( );
		}
		
 }
}